package lyx.game.utils
{
	import flash.ui.Keyboard;
	import flash.utils.describeType;
	
	/**
	 * KeySetting用于配置按键的控制设置。
	 * <p/>up，down，left，right表示方向键。
	 * <p/>start,select表示开始和选择键。
	 * <p/>action_n表示动作键。
	 * <p/>function_n表示功能键。
	 * <p/>extend_n表示扩展键（上述按键配置不满足需求时使用）。
	 */	
	public class KeySetting
	{
		public var up:int = Keyboard.UP;
		public var down:int = Keyboard.DOWN;
		public var left:int = Keyboard.LEFT;
		public var right:int = Keyboard.RIGHT;
		
		public var start:int = Keyboard.ENTER;
		public var select:int = Keyboard.SPACE;
		
		public var action_0:int = 74;
		public var action_1:int = 75;
		public var action_2:int = 76;
		public var action_3:int = 186;
		
		public var function_0:int = Keyboard.ESCAPE;
		public var function_1:int = -1;
		public var function_2:int = -1;
		public var function_3:int = -1;
		
		public var extend_0:int = -1;
		public var extend_1:int = -1;
		public var extend_2:int = -1;
		public var extend_3:int = -1;

		private var _setting_keys:XMLList;
		
		public function KeySetting()
		{
			_setting_keys = describeType(this).variable;
		}
		
		/**
		 * 验证keycode是否在KeySetting中 
		 * @param keycode
		 * @return keycode在KeySetting中，返回true，否则false。
		 * 
		 */		
		public function isValidKeyInSetting(keycode:int):Boolean
		{
			for each(var xml:XML in _setting_keys)
			{
				var variable_name:String = xml.@name;
				if(this[variable_name]==keycode)
				{
					return true;
				}
			}
			return false;
		}
	
	}
}